//index.js
//获取应用实例
const app = getApp();
// var template = require('../header/header.js');

Page({
    data: {
        radioList: [
            {name: '三轮车', value: 1},
                    // {name:'旧房翻新',value:2},
        ],
        valueCurry: 0,
        optionList: [],
        optionIndex: 0,
    },
    onLoad: function () {
        this.getTricycle();
    },
    onHide: function () {
    },
    onChange: function (e) {
        var index = e.detail.value;
        this.setData({
            optionIndex: index
        })
    },

    // 获取三轮车重量选项
    getTricycle: function () {
        var _this = this;
        var object = {
            url: app.api.url.other.tricycleOption,
            success: function (res) {
                _this.setData({
                    optionList: res.data
                })
            }
        }
        app.request(object);
    },

    // 计算
    submit: function (e) {
        var data = e.detail.value;
        var index = this.data.optionIndex;
        data.option_id = this.data.optionList[index]['id'];
        var object = {
            url: app.api.url.other.tricycle,
            data: data,
            success: function (res) {
                if (res.status == 1) {
                    wx.showModal({title: '计算结果', content: '根据您填写的信息，您需要' + res.data.num + '辆三轮车，运费'+res.data.price+'元',showCancel:false});
                } else {
                    wx.showToast({title:res.info});
                }
            }
        }
        app.request(object);
    }
});
